package tr.edu.ege.kipler.satisfiability.container;

import java.util.Iterator;

import tr.edu.ege.kipler.common.RelationalValue;
import tr.edu.ege.kipler.syntax.Name;
import tr.edu.ege.kipler.syntax.NameManager;
import tr.edu.ege.kipler.syntax.concept.Concept;
import tr.edu.ege.kipler.syntax.concept.ConceptName;

/**
 * 
 * @author İnanç Seylan
 *
 */
public class Individual implements RelationalValue<Individual, Name> {
	protected Name name;

	protected ConceptCategorizer categorizer = new ConceptCategorizer();

	public Individual() {
		categorizer.add(ConceptName.topConcept());
	}

	public Individual(String name) {
		setName(name);
		add(ConceptName.topConcept());
	}

	public Iterator<Concept> conceptIterator() {
		return categorizer.conceptIterator();
	}

	public Iterator<Concept> conceptIterator(ConceptCategory category) {
		return categorizer.categoryIterator(category);
	}

	public String getName() {
		return name.toString();
	}

	public void setName(String name) {
		this.name = NameManager.getInstance().getName(name);
	}

	public Name getKey() {
		return name;
	}

	public Individual copy() {
		Individual node = new Individual();
		node.name = name;
		node.categorizer = categorizer.copy();
		return node;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj != null && (obj.getClass().equals(this.getClass()))) {
			Individual other = (Individual) obj;
			return name.equals(other.name);
					//&& categorizer.equals(other.categorizer);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return 17 * 37 + name.hashCode();
	}

	public void add(Concept concept) {
		categorizer.add(concept);
	}

	public boolean contains(Concept concept) {
		return categorizer.contains(concept);
	}

	public boolean containsAllConceptsOf(Individual other) {
		return categorizer.containsAllConceptsOf(other.categorizer);
	}

	public boolean hasSameConceptsAs(Individual other) {
		return categorizer.hasSameConceptsAs(other.categorizer);
	}

	@Override
	public String toString() {
		return name.toString();
	}

}
